<?php 
session_start();
if (isset($_SESSION['openid']) && isset($_POST['p']) && isset($_POST['code'])){
    if (isset($_SESSION['code'])){
        $code=trim($_POST['code']);
        if ($code != $_SESSION['code']){
            echo json_encode(array('s'=>'n','e'=>'code'));
            exit;
        } 
    }else{
        echo json_encode(array('s'=>'n','e'=>'code'));
        exit;
    }
    
    if (empty($_POST['p'])){
        echo json_encode(array('s'=>'n','e'=>'code'));
        exit;
    }
    
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    $sql="update ".$tableVer."_users set phone='".addslashes(trim($_POST['p']))."' where openid='".$_SESSION['openid']."'";
    $query = $mysqli->query($sql);
    echo json_encode(array('s'=>'y'));
}